package ru.kruzhki.client.ui.main;

import ru.kruzhki.client.gwtp.AbstractView;

import com.google.common.collect.ImmutableBiMap;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class MainPageView extends AbstractView<Label> implements MainPagePresenter.MyView {

	static final ImmutableBiMap<Type<?>,String> ID_BY_SLOT=ImmutableBiMap.<Type<?>,String>builder()
			.put(MainPagePresenter.TYPE_header,"header")
			.put(MainPagePresenter.TYPE_content,"content")	
			.put(MainPagePresenter.TYPE_sideLeft,"sideLeft")
			.put(MainPagePresenter.TYPE_sideRight,"sideRight")
			.put(MainPagePresenter.TYPE_footer,"footer")
			.build();

	@Inject
	public MainPageView() {
	}

	
	@Override
	public void setInSlot(Object slot, Widget content) {
		String elementId=ID_BY_SLOT.get(slot);
		if(elementId==null){
			throw new IllegalStateException("Slot "+slot+" not found.");
		}
		RootPanel elementPanel = RootPanel.get(elementId);
		elementPanel.clear();
		elementPanel.add(content);
	}

	@Override
	protected Label createWidget() {
		Label label = new Label();
		label.setVisible(false);
		return label;
	}
}
